<template>
    <div class="flex row" v-if="item">
        <div class="book-image">
            <image class="image" @appear="onAppear" @disappear="disAppear" :src=" imageUrl"></image>
        </div>
        <div class="book-info">
            <text class="title margin-bottom">{{item.title}}</text>
            <text class="desc margin-bottom">{{item.shortIntro}}</text>
            <div class="other-info row margin-bottom">
                <div class="other-info-left row">
                    <image class="author-image" :src="author_icon"></image>
                    <text class="author">{{item.author}}</text>
                </div>
                <div class="other-info-right row">
                    <text class="popularity">{{item.latelyFollower || "0"}} 人气</text>
                    <text class="keep">{{item.retentionRatio || "0.0"}}% 留存</text>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import {author_icon, getImageUrl, isRealImageUrl, book_default_img} from '../../baseConfig';
    export default {
        name: "book-item",
        props:{
            index:{
                type: Number,
                default: 0,
            },
            item:{
                type: Object,
                default: undefined,
            }
        },
        data(){
            return{
                author_icon: author_icon,
                imageUrl: '',
                isOnAppear:false,
                isDisAppear:true,
            }
        },
        computed:{
            realImageUrl(){
                return getImageUrl(this.item.cover);
            }
        },
        mounted(){
            this.imageUrl = book_default_img
        },
        methods:{
            onAppear(){
                this.isOnAppear = true;
                if(!isRealImageUrl(this.imageUrl)){
                    this.imageUrl = this.realImageUrl;
                }
            },
            disAppear(){
                this.isOnAppear = false;
            }
        },
        watch:{
            item(){
                if(this.isOnAppear){
                    this.imageUrl = this.realImageUrl;
                }else{
                    this.imageUrl = book_default_img;
                }
            }
        }
    }
</script>

<style scoped>
    .flex{
        flex: 1;
        width: 750px;
    }
    .row {
        flex-direction: row;
    }

    .desc,
    .author,
    .keep,
    .popularity {
        font-size: 24px;
        color: #666666;
    }

    .book-info {
        flex: 1;
        padding: 10px 20px 0 16px;
    }

    .margin-bottom {
        margin-bottom: 20px;
    }

    .image {
        width: 182px;
        height: 230px;
    }

    .book-info {
        flex: 2;
    }

    .title {
        font-weight: 400;
        font-size: 32px;
        lines: 1;
    }

    .desc {
        lines: 2;
    }

    .other-info {
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .other-info-left{
        justify-content: flex-start;
    }
    .other-info-right{
        justify-content: flex-end;
    }
    .other-info-left, .other-info-right {
        /*justify-content: center;*/
        align-items: center;
    }

    .author-image {
        width: 26px;
        height: 26px;
        margin-right: 5px;
    }

    .author {
    }

    .popularity, .keep {
        border-style: solid;
        border-width: 1px;
        justify-content: center;
        align-items: center;
        padding: 5px;
    }

    /* 人气 */
    .popularity {
        color: #d81e06;
        border-color: #d81e06;
        margin-right: 10px;
    }

    .keep {
        color: #4284ed;
        border-color: #4284ed;
    }
</style>